package cn.iocoder.yudao.module.bpm.dal.mysql.taskinfo;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.bpm.dal.dataobject.taskinfo.BpmTaskInfoDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.bpm.controller.admin.taskinfo.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 流程任务信息 Mapper
 *
 * @author 韩佳乐
 */
@Mapper
public interface BpmTaskInfoMapper extends BaseMapperX<BpmTaskInfoDO> {

    default PageResult<BpmTaskInfoDO> selectPage(BpmTaskInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BpmTaskInfoDO>()
                .eqIfPresent(BpmTaskInfoDO::getCode, reqVO.getCode())
                .likeIfPresent(BpmTaskInfoDO::getName, reqVO.getName())
                .eqIfPresent(BpmTaskInfoDO::getType, reqVO.getType())
                .eqIfPresent(BpmTaskInfoDO::getFormId, reqVO.getFormId())
                .eqIfPresent(BpmTaskInfoDO::getAdminId, reqVO.getAdminId())
                .eqIfPresent(BpmTaskInfoDO::getConfirmId, reqVO.getConfirmId())
                .eqIfPresent(BpmTaskInfoDO::getAttentionId, reqVO.getAttentionId())
                .eqIfPresent(BpmTaskInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(BpmTaskInfoDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BpmTaskInfoDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(BpmTaskInfoDO::getTagId, reqVO.getTagId())
                .eqIfPresent(BpmTaskInfoDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(BpmTaskInfoDO::getParentId, reqVO.getParentId())
                .eqIfPresent(BpmTaskInfoDO::getRelationId, reqVO.getRelationId())
                .betweenIfPresent(BpmTaskInfoDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BpmTaskInfoDO::getDescription, reqVO.getDescription())
                .eqIfPresent(BpmTaskInfoDO::getOrderRank, reqVO.getOrderRank())
                .eqIfPresent(BpmTaskInfoDO::getCreator, reqVO.getCreator())
                .eqIfPresent(BpmTaskInfoDO::getProjectId, reqVO.getProjectId())
                .orderByDesc(BpmTaskInfoDO::getId));
    }

    @Update("UPDATE bpm_task_info SET status = #{status} , update_time = sysdate() where id = #{id}")
    void updateTaskInfoStatusById(@Param("id") Long id,@Param("status") int status);

}